package com.hmall.common.config;

import com.hmall.common.interceptor.UserInfoInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 张文接
 * @version 1.0
 * @createTime 2024/7/23 22:32
 */
@Configuration
/*
  作用：条件判断，当父模块有DispatcherServlet类时才会去自动装配改配之类，本案例是gateway防止gateway模块去实例化改配之类而导致报错，因为
  gateway模块，没有引入SpringMVC的依赖
 */
@ConditionalOnClass(DispatcherServlet.class)//作用：条件判断，当父模块有DispatcherServlet类时才会去自动装配改配之类，
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInfoInterceptor());
    }
}
